package cn.tedu._05mvcboot03.common.response;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
//    同意反馈相应
@Setter
@Getter
@AllArgsConstructor
@NoArgsConstructor
public class JsonResult {
    private Integer state;
    private String message;
    private Object data;

//    1.没有返回参数的
    public JsonResult(StatusCode statusCode){
        this.state=statusCode.getStatus();
        this.message=statusCode.getMessage();
    }

//    2.有返回参数的
    public JsonResult(StatusCode statusCode,Object data){
        this.state=statusCode.getStatus();
        this.message=statusCode.getMessage();
        this.data=data;
    }

//    3.有返回值的静态方法(方便调用)
    public static JsonResult ok(Object data){
        return new JsonResult(StatusCode.OPERATION_SUCCESS,data);
    }

//    4.无返回值的静态方法
    public static JsonResult ok(){
        return JsonResult.ok(null);
    }

}
